<template>
  <div>
    <hd-tab :tabs="tabs"></hd-tab>

    <el-card class="box-card" shadow="never">
      <div slot="header" class="clearfix">
        <span v-if="this.id">编辑桌台</span>
        <span v-else>添加桌台</span>
      </div>
      <el-form :model="form" label-width="80px">
        <el-form-item label="桌台名称">
          <el-input v-model="form.name"></el-input>
          <hd-error name="name"></hd-error>
        </el-form-item>
        <el-form-item label="二维码">
          <hd-image v-model="form.image"></hd-image>
          <hd-error name="image"></hd-error>
        </el-form-item>
      </el-form>

    </el-card>
    <el-button class="mt-3" type="primary" @click="onSubmit">提交</el-button>
  </div>
</template>

<script>
import tabs from './tabs.js'

export default {
  route: false,
  props: ['id'],
  data() {
    return {
      form: {},
      tabs
    }
  },
  async created() {
    if (this.id) {
      this.form = await this.axios.get(`admin/desk/${this.id}`)
    }
  },
  methods: {
    async load() {
      if (this.id) {
        this.form = await this.axios.get(`admin/desk/${this.id}`)
      }
    },
    async onSubmit() {
      const url = this.id ? `admin/desk/${this.id}` : `admin/desk`
      await this.axios[this.id ? "put" : "post"](url, this.form)
      this.$router.push({name: 'admin.desk.index'})
    }
  }

}
</script>

<style scoped>

</style>